// -----------------------------------------------------------------------
//  <copyright file="ResourceConfiguration.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025/1/6 23:55</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Authorization.Domain.Entities;


namespace DaprPlus.Identity.Infrastructure.EntityFrameworkCore.Configurations;

public class ResourceConfiguration : EntityConfigurationBase<Resource>
{
    /// <summary>
    /// 重写以实现实体类型各个属性的数据库配置
    /// </summary>
    /// <param name="builder">实体类型创建器</param>
    public override void Configure(EntityTypeBuilder<Resource> builder)
    {
        builder.Property(m => m.Name).IsRequired().HasMaxLength(500);
        builder.Property(m => m.Code).IsRequired().HasMaxLength(1000);
        builder.Property(m => m.Description).HasMaxLength(1000);
        builder.Property(m => m.ServiceName).IsRequired().HasMaxLength(500);
        builder.Property(m => m.MetadataJson).HasMaxLength(-1);
        builder.Property(m => m.AllowedOperationsJson).HasMaxLength(-1);

        builder.HasIndex(m => new { m.Code, m.ServiceName, m.Type }).HasDatabaseName("Code_ServiceName_Type_Index").IsUnique();
    }
}
